package com.groupjx.api;

import cn.hutool.core.bean.BeanUtil;
import com.groupjx.vo.*;

import java.util.HashMap;
import java.util.Map;

public class JXApi extends BaseApi {


    private static String LOGIN_PATH = "/member/auth/loginAccount";


    private static String USER_INFO_PATH = "/member/user/info";


    private static String GOODS_INFO_PAGE_PATH = "/goods/info/goodsInfoPage";


    private static String ORDER_SETTLEMENT_PATH = "/trade/order/settlement";


    private static String ORDER_CREATE_PATH = "/trade/order/create";


    private static String ORDER_PAGE_PATH = "/trade/order/page";


    private static String ORDER_CANCEL_PATH = "/trade/order/cancel";

    /**
     * 登录
     *
     * @param account
     * @param password
     * @return
     */
    public ResultVO login(String account, String password) {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("account", account);
        paramsMap.put("password", password);
        return execute(LOGIN_PATH, paramsMap, null);
    }


    /**
     * 获取用户信息
     *
     * @param token
     * @return
     */
    public ResultVO getUserInfo(String token) {
        Map<String, Object> paramsMap = new HashMap<>();
        return execute(USER_INFO_PATH, paramsMap, token);
    }


    /**
     * 获取商品信息
     *
     * @param token
     * @param reqVO
     * @return
     */
    public ResultVO getGoodsInfoPage(String token, GoodsInfopPageReqVO reqVO) {
        return execute(GOODS_INFO_PAGE_PATH, BeanUtil.beanToMap(reqVO, false, true), token);
    }


    /**
     * 结算
     *
     * @param token
     * @param reqVO
     * @return
     */
    public ResultVO settlement(String token, OrderSettlementReqVO reqVO) {
        return execute(ORDER_SETTLEMENT_PATH, BeanUtil.beanToMap(reqVO, false, true), token);
    }


    /**
     * 创建订单
     *
     * @param token
     * @param reqVO
     * @return
     */
    public ResultVO createOrder(String token, OrderCreateReqVO reqVO) {
        return execute(ORDER_CREATE_PATH, BeanUtil.beanToMap(reqVO, false, true), token);
    }


    /**
     * 订单分页
     *
     * @param token
     * @param reqVO
     * @return
     */
    public ResultVO orderPage(String token, OrderPageReqVO reqVO) {
        return execute(ORDER_PAGE_PATH, BeanUtil.beanToMap(reqVO, false, true), token);
    }


    /**
     * 取消订单
     *
     * @param token
     * @param reqVO
     * @return
     */
    public ResultVO cancelOrder(String token, OrderCancelReqVO reqVO) {
        return execute(ORDER_CANCEL_PATH, BeanUtil.beanToMap(reqVO, false, true), token);
    }


}
